<?php 

class Ext_Article_Show_Access
{
    public $edit   = false;
    public $delete = false;
    
    public function __construct($articleId)
    {
        $this->_build($articleId);
    }
    
    private function _build($articleId)
    {
        $articleRow = App_Model_DbTable_Article::getInstance()->getRowById($articleId);
        if(!isset($articleRow['userId']))
        {
            return "";
        }
        $userId = Ext_Auth_Front::getInstance()->getIdentity();
        if($userId == $articleRow['userId']){
            if(!$articleRow['firstReplyArticleId']){
                $this->edit   = true;
            }
            $this->delete = true;
            return "";
        }
        
        $user   = Ext_User::getInstance()->show($userId)->buildRole();
        $roleId   = $user->role->roleId;
        $roleType = $user->role->roleType;
        if($roleType != 'admin'){
            return "";
        }
        
        $zendAcl = Ext_Acl::getInstance()->build($roleId);
        if($zendAcl->isAllowed($roleId, 'article', 'update')) 
        {
            $this->edit = true;
        }
        if($zendAcl->isAllowed($roleId, 'article', 'delete')) 
        {
            $this->delete = true;
        }
        
        return ;
    }
    
}